/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 13754
 * @create 2023/11/29
 * @since 1.0.0
 */
package com.mengniu.commerce.collect.third.request;

import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.collect.third.WeiMengApi;
import com.mengniu.commerce.collect.third.response.order.OrderInfoResponse;
import com.mengniu.commerce.collect.third.response.order.OrderListResponse;
import com.mengniu.commerce.collect.util.RestTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微盟订单数据请求
 * @author 13754
 * @Date 2023/11/29 11:55
 * @Version 1.0.0
 */
@Service
public class IWeiMengRefundOrderRequest {

    private static String baseUrl ="https://dopen.weimob.com";

    private static String vid ="6001451595805";

    @Autowired
    RestTemplateUtil restTemplateUtil;

    /**
     * 分页查询订单列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    public OrderListResponse getRefundOrderList(int pageNum, int pageSize, String token){

        String url =baseUrl+ WeiMengApi.WM_REFUND_ORDER_LIST;
        JSONObject js = new JSONObject();
        js.put("pageNum",pageNum);
        js.put("pageSize",pageSize);
        JSONObject js2 = new JSONObject();
        //搜索时间，起止时间跨度不可大于 30 天。
        JSONObject queryTime = new JSONObject();
        //时间戳，毫秒级。
        queryTime.put("startTime","1645200000000");
        queryTime.put("endTime",System.currentTimeMillis());
        //0-创建时间；1-更新时间；2-支付时间
        queryTime.put("type",0);
        js2.put("queryTime",queryTime);
        //售后类型 1-退货退款；2-退款；5-退换货 退款进入售后订单
        js2.put("rightsTypes","[1,5]");
        js.put("queryParameter",js2);

        String result = restTemplateUtil.doPost(js, url,token);
        return  JSONObject.parseObject(result,OrderListResponse.class);
    }

    /**
     * 查询订单详情
     * @param rightsId
     * @return
     */
    public OrderInfoResponse getRefundOrderInfoById(Long rightsId, String token){
        String url =baseUrl+ WeiMengApi.WM_REFUND_ORDER_INFO;
        JSONObject js = new JSONObject();
        js.put("rightsId",rightsId);
        String result = restTemplateUtil.doPost(js, url,token);
        return  JSONObject.parseObject(result,OrderInfoResponse.class);
    }

}
